﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using System.Web.UI.HtmlControls;
using System.Data;

public partial class Admin_Page_SearchNews : BasePage
{
    TaiKhoan TK;
    protected void Page_Load(object sender, EventArgs e)
    {
        TK = (TaiKhoan)Session["TaiKhoan"];
        if (TK == null || (TK != null && TK.MaNhomQuyen != 1))
        {

            Response.Redirect("~/Admin/Page_Login.aspx");
        }

        if (!IsPostBack)
        {
            ((HtmlGenericControl)Master.FindControl("hPageTitle")).InnerText = "Tìm kiếm Tin tức";
        }

        
    }
 

    private void TimKiem()
    {
        SqlDataSource2.FilterExpression = "1=1";
        if (ddlTheLoai.SelectedIndex != 0)
        {
            SqlDataSource2.FilterExpression += " AND [MaLoaiTT] = " + ddlTheLoai.SelectedValue;
        }
        if (txtTuKhoa.Text != "")
        {
            SqlDataSource2.FilterExpression += " AND [TieuDe] LIKE '%" + txtTuKhoa.Text + "%'";
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TimKiem();
    }
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        TimKiem();
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        TimKiem();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        
        if (e.Row.DataItem != null)
        {
            TinTuc tt = TTBLL.LayTheoMa((int)((DataRowView)e.Row.DataItem)["Ma"]);
            e.Row.Cells[2].Text = tt.LoaiTinTuc.Ten;
        }
    }
}
